<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>vue/vuecli4搭建新项目，并引入element | Han's Blog</title><meta name="keywords" content="vue,element"><meta name="author" content="憨憨一个"><meta name="copyright" content="憨憨一个"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="description" content="一、vue create my-projectname1vue create my-projectname  这边可以直接选择默认的配置，我选择了最后一个自己配置sass，babel，route，vuex，eslint  二、添加elementelement 官网(https:&#x2F;&#x2F;element.eleme.cn&#x2F;#&#x2F;zh-CN&#x2F;component&#x2F;quickstart) 这里值得注意！！vue@">
<meta property="og:type" content="article">
<meta property="og:title" content="vue&#x2F;vuecli4搭建新项目，并引入element">
<meta property="og:url" content="http://blog.better2020.top/2021/10/09/vue-vuecli4%E6%90%AD%E5%BB%BA%E6%96%B0%E9%A1%B9%E7%9B%AE%EF%BC%8C%E5%B9%B6%E5%BC%95%E5%85%A5element/index.html">
<meta property="og:site_name" content="Han&#39;s Blog">
<meta property="og:description" content="一、vue create my-projectname1vue create my-projectname  这边可以直接选择默认的配置，我选择了最后一个自己配置sass，babel，route，vuex，eslint  二、添加elementelement 官网(https:&#x2F;&#x2F;element.eleme.cn&#x2F;#&#x2F;zh-CN&#x2F;component&#x2F;quickstart) 这里值得注意！！vue@">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://blog.better2020.top/2021/10/09/vue-vuecli4%E6%90%AD%E5%BB%BA%E6%96%B0%E9%A1%B9%E7%9B%AE%EF%BC%8C%E5%B9%B6%E5%BC%95%E5%85%A5element/topimg.png">
<meta property="article:published_time" content="2021-10-09T05:13:05.000Z">
<meta property="article:modified_time" content="2022-03-17T05:25:20.696Z">
<meta property="article:author" content="憨憨一个">
<meta property="article:tag" content="vue">
<meta property="article:tag" content="element">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://blog.better2020.top/2021/10/09/vue-vuecli4%E6%90%AD%E5%BB%BA%E6%96%B0%E9%A1%B9%E7%9B%AE%EF%BC%8C%E5%B9%B6%E5%BC%95%E5%85%A5element/topimg.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://blog.better2020.top/2021/10/09/vue-vuecli4%E6%90%AD%E5%BB%BA%E6%96%B0%E9%A1%B9%E7%9B%AE%EF%BC%8C%E5%B9%B6%E5%BC%95%E5%85%A5element/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="preconnect" href="//zz.bdstatic.com"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css"><script>var GLOBAL_CONFIG = { 
  root: '/',
  hexoversion: '5.2.0',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  ClickShowText: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  justifiedGallery: {
    js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
    css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
};

var saveToLocal = {
  set: function setWithExpiry(key, value, ttl) {
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isSidebar: true,
  postUpdate: '2022-03-17 13:25:20'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(function () {
  window.activateDarkMode = function () {
    document.documentElement.setAttribute('data-theme', 'dark')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
    }
  }
  window.activateLightMode = function () {
    document.documentElement.setAttribute('data-theme', 'light')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
    }
  }

  const autoChangeMode = 'false'
  const t = saveToLocal.get('theme')
  if (autoChangeMode === '1') {
    const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
    const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
    const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
    const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified

    if (t === undefined) {
      if (isLightMode) activateLightMode()
      else if (isDarkMode) activateDarkMode()
      else if (isNotSpecified || hasNoSupport) {
        const now = new Date()
        const hour = now.getHours()
        const isNight = hour <= 6 || hour >= 18
        isNight ? activateDarkMode() : activateLightMode()
      }
      window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
        if (saveToLocal.get('theme') === undefined) {
          e.matches ? activateDarkMode() : activateLightMode()
        }
      })
    } else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else if (autoChangeMode === '2') {
    const now = new Date()
    const hour = now.getHours()
    const isNight = hour <= 6 || hour >= 18
    if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
    else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else {
    if (t === 'dark') activateDarkMode()
    else if (t === 'light') activateLightMode()
  }
})()</script><meta name="generator" content="Hexo 5.2.0"><link rel="alternate" href="/atom.xml" title="Han's Blog" type="application/atom+xml">
</head><body><div id="mobile-sidebar"><div id="menu_mask"></div><div id="mobile-sidebar-menus"><div class="mobile_author_icon"><img class="avatar-img" src="/null" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="mobile_post_data"><div class="mobile_data_item is-center"><div class="mobile_data_link"><a href="/archives/"><div class="headline">文章</div><div class="length_num">25</div></a></div></div><div class="mobile_data_item is-center">      <div class="mobile_data_link"><a href="/tags/"><div class="headline">标签</div><div class="length_num">16</div></a></div></div><div class="mobile_data_item is-center">     <div class="mobile_data_link"><a href="/categories/"><div class="headline">分类</div><div class="length_num">2</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div></div></div></div><div id="body-wrap"><div id="sidebar"><i class="fas fa-arrow-right on" id="toggle-sidebar"></i><div class="sidebar-toc"><div class="sidebar-toc__title">目录</div><div class="sidebar-toc__progress"><span class="progress-notice">你已经读了</span><span class="progress-num">0</span><span class="progress-percentage">%</span><div class="sidebar-toc__progress-bar">     </div></div><div class="sidebar-toc__content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%80%E3%80%81vue-create-my-projectname"><span class="toc-number">1.</span> <span class="toc-text">一、vue create my-projectname</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E6%B7%BB%E5%8A%A0element"><span class="toc-number">2.</span> <span class="toc-text">二、添加element</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%A2%8E%E7%A2%8E%E5%BF%B5"><span class="toc-number">3.</span> <span class="toc-text">碎碎念</span></a></li></ol></div></div></div><header class="post-bg" id="page-header" style="background-image: url(/2021/10/09/vue-vuecli4%E6%90%AD%E5%BB%BA%E6%96%B0%E9%A1%B9%E7%9B%AE%EF%BC%8C%E5%B9%B6%E5%BC%95%E5%85%A5element/topimg.png)"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Han's Blog</a></span><span id="menus"><div id="search_button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div></div><span class="close" id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></span></span></nav><div id="post-info"><div id="post-title"><div class="posttitle">vue/vuecli4搭建新项目，并引入element</div></div><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-10-09T05:13:05.000Z" title="发表于 2021-10-09 13:13:05">2021-10-09</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-03-17T05:25:20.696Z" title="更新于 2022-03-17 13:25:20">2022-03-17</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/code/">code</a></span></div><div class="meta-secondline"> <span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout_post" id="content-inner"><article id="post"><div class="post-content" id="article-container"><h2 id="一、vue-create-my-projectname"><a href="#一、vue-create-my-projectname" class="headerlink" title="一、vue create my-projectname"></a>一、vue create my-projectname</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vue create my-projectname</span><br></pre></td></tr></table></figure>
<img src="/2021/10/09/vue-vuecli4%E6%90%AD%E5%BB%BA%E6%96%B0%E9%A1%B9%E7%9B%AE%EF%BC%8C%E5%B9%B6%E5%BC%95%E5%85%A5element/1.png" alt="创建项目选择配置" width="500">
这边可以直接选择默认的配置，我选择了最后一个自己配置sass，babel，route，vuex，eslint

<h2 id="二、添加element"><a href="#二、添加element" class="headerlink" title="二、添加element"></a>二、添加element</h2><p>element 官网(<a target="_blank" rel="noopener" href="https://element.eleme.cn/#/zh-CN/component/quickstart">https://element.eleme.cn/#/zh-CN/component/quickstart</a>)</p>
<p>这里值得注意！！vue@cli4直接一行命令搞定按需引入</p>
<blockquote>
<p>vue add element</p>
</blockquote>
<p>这样项目文件中多了如图所示的plugin文件夹，里面的element.js中用于添加你需要引入的element模块。<br>main.js已经自行引入了此文件，接下来只需要使用即可</p>
<h2 id="碎碎念"><a href="#碎碎念" class="headerlink" title="碎碎念"></a>碎碎念</h2><p>之前根据element文档后面的按需引入来进行操作，发现找不到 babelrc文件，原来现在变成了babel.config.js,<br>而且只需要一行命令就完美配置，真的牛</p>
</div><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">憨憨一个</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://blog.better2020.top/2021/10/09/vue-vuecli4%E6%90%AD%E5%BB%BA%E6%96%B0%E9%A1%B9%E7%9B%AE%EF%BC%8C%E5%B9%B6%E5%BC%95%E5%85%A5element/">http://blog.better2020.top/2021/10/09/vue-vuecli4%E6%90%AD%E5%BB%BA%E6%96%B0%E9%A1%B9%E7%9B%AE%EF%BC%8C%E5%B9%B6%E5%BC%95%E5%85%A5element/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://blog.better2020.top" target="_blank">Han's Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/vue/">vue</a><a class="post-meta__tags" href="/tags/element/">element</a></div><div class="post_share"><div class="social-share" data-image="/2021/10/09/vue-vuecli4%E6%90%AD%E5%BB%BA%E6%96%B0%E9%A1%B9%E7%9B%AE%EF%BC%8C%E5%B9%B6%E5%BC%95%E5%85%A5element/topimg.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2022/02/25/BFC%E5%88%B0%E5%BA%95%E6%98%AF%E4%BB%80%E4%B9%88/"><img class="prev-cover" src="/2022/02/25/BFC%E5%88%B0%E5%BA%95%E6%98%AF%E4%BB%80%E4%B9%88/top_img.png" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">BFC到底是什么</div></div></a></div><div class="next-post pull-right"><a href="/2021/09/03/%E9%9D%A2%E8%AF%95%E6%97%A5%E8%AE%B0/"><img class="next-cover" src="/2021/09/03/%E9%9D%A2%E8%AF%95%E6%97%A5%E8%AE%B0/top_img.png" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">面试日记</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2021/03/31/vue-v-show状态值改变，视图未更新/" title="vue v-show状态值改变，视图未更新"><img class="cover" src="/images/%E5%86%AC%E9%9B%AA.jpg"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-03-31</div><div class="title">vue v-show状态值改变，视图未更新</div></div></a></div><div><a href="/2021/08/04/vue瀑布流布局/" title="vue瀑布流布局"><img class="cover" src="/2021/08/04/vue%E7%80%91%E5%B8%83%E6%B5%81%E5%B8%83%E5%B1%80/%E7%80%91%E5%B8%83%E6%B5%81.png"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-08-04</div><div class="title">vue瀑布流布局</div></div></a></div><div><a href="/2020/10/28/vue环境搭建/" title="记录从零搭建Vue-cli"><img class="cover" src="/images/%E5%86%AC%E9%9B%AA.jpg"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-10-28</div><div class="title">记录从零搭建Vue-cli</div></div></a></div><div><a href="/2021/09/02/vue生命周期/" title="vue生命周期"><img class="cover" src="/2021/09/02/vue%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F/lifecycle.png"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-09-02</div><div class="title">vue生命周期</div></div></a></div><div><a href="/2021/03/31/vue项目中引用iconfont/" title="vue项目中引用iconfont"><img class="cover" src="/2021/03/31/vue%E9%A1%B9%E7%9B%AE%E4%B8%AD%E5%BC%95%E7%94%A8iconfont/01.png"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-03-31</div><div class="title">vue项目中引用iconfont</div></div></a></div></div></div></article></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By 憨憨一个</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><section id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></section><div class="search-dialog" id="local-search"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a target="_blank" rel="noopener" href="https://github.com/wzpan/hexo-generator-search" style="color:#49B1F5;">hexo-generator-search</a>
 <span>提供支持</span></div></div></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div><div><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script>(function(){
  const bp = document.createElement('script');
  const curProtocol = window.location.protocol.split(':')[0];
  if (curProtocol === 'https'){
  bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
  }
  else{
  bp.src = 'http://push.zhanzhang.baidu.com/push.js';
  }
  bp.dataset.pjax = ''
  const s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(bp, s);
})()</script></div></body></html>